package game.line;

import android.graphics.Bitmap;
import android.graphics.Rect;

public class Sprite {
	private Bitmap bmp;
	private int column;
	private int row;
	private int numberFrame;
	private int speed;
	private int width;
	private int height;
	private int x = 0;
    private int y = 0;
	private GameView gameview;
	private int currentFrame = 0;
	public Sprite()
	{
		
	}
	public Sprite(GameView gameView, Bitmap bmp, int column, int row) {
        this.gameview = gameView;
        this.bmp = bmp;
        this.row=row;
        this.column=column;
        this.width = bmp.getWidth() / column;
        this.height = bmp.getHeight() / row;
  }
  private void update() {
        if (x > gameview.getWidth() - width - speed) {
               speed = -5;
        }
        if (x + speed < 0) {
               speed = 5;
        }
        x = x + speed;
        currentFrame = ++currentFrame % column;
  }
  //get Sprite from Bitmap bmp, position (column,row), place (posx,posy), with width,height
  public void drawSprite(Bitmap bmp,int column,int row,int posx,int posy,int width,int height)
	{
	  /*int srcX = 2 * 30;
      int srcY = 0;
      System.out.println("Draw ball");
      Rect src = new Rect(srcX, srcY, srcX + 30, srcY + 30);
      Rect dst = new Rect(posx, posy, posx + 30, posy + 30);
      gameview.c.drawBitmap(bmp, src, dst, null);*/
	  int srcX = column * width;
      int srcY = row * height;
      Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
      Rect dst = new Rect(posx, posy, posx + width, posy + height);
      gameview.c.drawBitmap(bmp, src, dst, null);
	}
}
